package e.odbo.data.mock;

import e.odbo.data.generator.Generator;
import e.odbo.data.model.*;
import e.odbo.data.model.smaple.PK;
import e.odbo.data.model.smaple.TimeLogAble;

import static e.odbo.data.model.ColumnType.*;

public class TableMock {

    public static Table getDemo(){
        return new Table("demo")
                .implement(PK.PK_Int)
                .Column("name",VARCHAR(255))
                .Column("age",INT)
                .Column("sex",BOOLEAN);
    }

    public static Table getDemo(String tableName){
        return new Table(tableName)
                .implement(PK.PK_Int)
                .Column("name",VARCHAR(255))
                .Column("age",INT)
                .Column("sex",BOOLEAN);
    }

    public static Table getDemoWithComment(){
        return new Table("demo1")
                .implement(PK.PK_Int)
                .Column("name", VARCHAR(255),"姓名")
                .Column("age",INT,"年龄")
                .Column("sex",BOOLEAN,"性别")
                .comment("示列2");
    }

    public static Table getDemoWithRefDemoTable(){
        Column ref=Column.c("refdemo",ColumnType.INT).ref("demo",PK.Column_Name);
        return new Table("demo2")
                .implement(PK.PK_Int)
                .Column("name", VARCHAR(255))
                .Column("age",INT)
                .Column("sex",BOOLEAN)
                .addColumn(ref);
    }

    public static Table getDemoWithRefDemoTable(Table refTable,boolean cascade){
        return new Table("demo3")
                .implement(PK.PK_Int)
                .Column("name", VARCHAR(255))
                .Column("age",INT)
                .Column("sex",BOOLEAN)
                .ref(refTable,cascade);
    }

    public static Table getDemoWithALL(Table refTable){
        return new Table("demoWithAll")
                .implement(PK.PK_Int, TimeLogAble.Instance)
                .Column("name", VARCHAR(255),"姓名")
                .Column("age",INT,"年龄")
                .Column("sex",BOOLEAN.defaultV(true),ColumnFlag.NotNull&ColumnFlag.Index)
                .addColumn(Column.c("addr", VARCHAR(500)).NotNull().comment("地址"),
                           Column.c("addr1", VARCHAR(500)).comment("地址1"),
                           Column.c("tel", VARCHAR(20).defaultGenerator(Generator.TELEPHONE),"电话"))
                .ref(refTable,true)
                .comment("全功能示列表");
    }

    public static Table[] getAllTables(){
        Table demo=getDemo();
        return new Table[]{
                demo,
                getDemoWithComment(),
                getDemoWithRefDemoTable(),
                getDemoWithRefDemoTable(demo,false),
                getDemoWithALL(demo)
        };
    }

    public static Table getClobTable(){
        Table themeUI=new Table("theme_ui").implement(PK.PK_String);
        themeUI.addColumn(
                Column.c("name", VARCHAR(30),"样式名称").NotNull(),
                Column.c("clock_type", INT,"数字0，模似1").NotNull(),
                Column.c("config_text",CLOB,"jsons格式设置").NotNull()
        );
        return themeUI;
    }
}
